package com.test.hanlp.starter;

import com.test.hanlp.config.FileConfig;
import com.test.hanlp.participle.service.IWordVerifiedService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationContext;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * @author : ky.zhang
 * @description :
 * @createDate : 2024/8/13 13:53
 */
@Component
public class MyStarter {
    private final IWordVerifiedService iWordVerifiedService;
    private final ApplicationContext applicationContext;
    private final FileConfig fileConfig;

    public MyStarter(IWordVerifiedService iWordVerifiedService, ApplicationContext applicationContext, FileConfig fileConfig) {
        this.iWordVerifiedService = iWordVerifiedService;
        this.applicationContext = applicationContext;
        this.fileConfig = fileConfig;
    }

    @EventListener(ApplicationReadyEvent.class)
    public void onApplicationReadyEvent() {
        for (String tablePath : fileConfig.getTablePaths()) {
            iWordVerifiedService.verified(tablePath);
        }
        int exitCode = SpringApplication.exit(applicationContext, () -> 0);
        System.exit(exitCode);
    }
}
